#include "stdio.h"
#include "stdlib.h"
#include "string.h"

/*
 * test_1使用到的结构体
 */
typedef struct{
    char data[20];
    int num;
}Address;

typedef struct{
    char name [20];
    Address addr;
}Person;

/*
 * test_2 test_3使用到的结构体
 */
typedef struct{
    char data[20];
    int num;
}Address2;

typedef struct{
    char name [20];
    Address2 *addr;
}Person2;

void test_1()
{
    Person *iroan = (Person *)malloc(sizeof(Person));
    int size = sizeof(Person);
    printf("Person size=%d\n",size);

    size = sizeof(Address);
    printf("Address size=%d\n",size);

    strcpy(iroan->name,"wangkaixuan");
    strcpy(iroan->addr.data,"China");
    iroan->addr.num = 12;

    printf("name=%s\n",iroan->name);
    printf("data=%s\n",iroan->addr.data);
    printf("num=%d\n",iroan->addr.num);
}
void test_2()
{
    printf("test_2\n");
    Person2 *iroan = (Person2 *)malloc(sizeof(Person2));
    int size = sizeof(Person2);
    printf("Person size=%d\n",size);

    size = sizeof(Address2);
    printf("Address size=%d\n",size);

    strcpy(iroan->name,"wangkaixuan");
    strcpy(iroan->addr->data,"China");
    iroan->addr->num = 12;

    printf("name=%s\n",iroan->name);
    printf("data=%s\n",iroan->addr->data);
    printf("num=%d\n",iroan->addr->num);
}
void test_3()
{
    printf("test_2\n");
    Person2 *iroan = (Person2 *)malloc(sizeof(Person2));
    iroan->addr = (Address2 *)malloc(sizeof(Address2));

    int size = sizeof(Person2);
    printf("Person size=%d\n",size);

    size = sizeof(Address2);
    printf("Address size=%d\n",size);

    strcpy(iroan->name,"wangkaixuan");
    strcpy(iroan->addr->data,"China");
    iroan->addr->num = 12;

    printf("name=%s\n",iroan->name);
    printf("data=%s\n",iroan->addr->data);
    printf("num=%d\n",iroan->addr->num);
}

int main(int argc, char const *argv[])
{
    if(argc > 2){
        printf("Usage: option,option=1 or 2 or 3\n");
    }

    if(*argv[1] == '1'){
        test_1();
    }
    if(*argv[1] == '2'){
        test_2();
    }
    if(*argv[1] == '3'){
        test_3();
    }
    return 0;
}
